package com.synjones.handsetS8.pages;
/**
 * 新中新手持机二代证指纹开发例程
 * 添加连续读卡  时间和次数统计    添加读卡超时进入休眠的功能
 * 有指纹扫描和显示功能
 */

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.synjones.handsetS8.R;;
import com.synjones.handsetS8.PictureFaceMatch.TakePhotoActivity;
import com.synjones.handsetS8.Utils.preferences.LocalSharedPreferences;
import com.synjones.handsetS8.Utils.preferences.SPNameInterface;
import com.synjones.handsetS8.Utils.util;
import com.synjones.handsetS8.facesdk.FaceAuthAsync;
import com.synjones.handsetS8.facesdk.FaceHandle;
import com.synjones.handsetS8.fp.FPTestActivity;
import com.synjones.handsetS8.fp.FindFpModuleAsyncTask;
import com.synjones.handsetS8L.MyUtils;
import com.synjones.idcard.CountryCode;
import com.synjones.idcard.ForeignerIDCard;
import com.synjones.idcard.IDCard;
import com.synjones.idcard.IDCardReaderRetInfo;
import com.synjones.reader.IDCardReaderModule;

import java.io.File;

public class DemoActivity extends Activity {

    public static final int ALGORITHM_VERSION = 2;

    //捷知公司读取身份证
    private Button btnIdCardRead;

    private Button buttonReadCard;
    private CheckBox cbReadCardFp;
    private Button buttonExit;
    private Button btnFingerprint;
    OnClickListener listenerReadCard = null;
    public IDCardReaderModule idCardReaderModule;
    private Bitmap bmp;
    private volatile boolean reading = false;
    private TextView tvCount;
    private TextView tvSuccessCount;
    private TextView tvFailCount;
    private TextView tvTime;
    private TextView tvMsg;
    private long eclipseTime = 0;
    private long ReadCount = 0;
    private long SuccessCount = 0;
    private long FailCount = 0;

    private static final int ReadOnceDone = 0x01;
    private static final int UpDateTime = 0x04;
    private static final int ReadSamvDone = 0x08;
    private static final int ReadThreadDone = 0x09;
    ProgressDialog pd;
    int readCount = 0;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case ReadOnceDone:
                    showIDcardInfo((IDCard) msg.obj);//读卡成功，显示身份证信息
				/*	readCount++;
                    if(readCount>=10){
                        String msgLog="time="+myTools.getDate()+", readCount="+ReadCount+", success count="+SuccessCount+"\r\n";
                        readCount=0;
                        myTools.appendByte2SdcardFile(myTools.getExternalPath()+"readLog.txt",msgLog.getBytes());
                    }*/
                    break;
                case UpDateTime:
                    eclipseTime++;
                    tvTime.setText("时间：" + util.formatDuringm(eclipseTime * 1000));
                    LocalSharedPreferences.setString(getApplicationContext(), SPNameInterface.SP_TIME, "" + eclipseTime);
                    break;
                case ReadSamvDone:
                    String message = "获取samvID失败";
                    if (msg.obj != null) {
                        message = "保存samvID失败";
                        if (MyUtils.fileIsExists(MyUtils.getExternalPath() + "samvID")) {
                            File file = new File(MyUtils.getExternalPath() + "samvID");
                            file.delete();
                        }
                        if (MyUtils.writeStr2SdcardFile(MyUtils.getExternalPath() + "samvID", "" + msg.obj)) {
                            message = "保存samvID成功，samvID=" + msg.obj;
                        }
                    }
                    try {
                        pd.dismiss();
                    } catch (Exception e) {
                    }
                    new AlertDialog.Builder(DemoActivity.this)
                            .setTitle("提示")
                            .setMessage(message)
                            .setPositiveButton("确定", null).show();

                    break;
                case ReadThreadDone:
                    buttonReadCard.setText("读卡");
                    tvMsg.setText("stop");
                    break;
            }

            super.handleMessage(msg);
        }
    };
    ;
    private ReadCardThread ReadCardThreadhandler;
    private MediaPlayer mediaPlayer = null;//读卡音
    CardInfoView cardInfoView;
    private String status = "";
    boolean boolReadFringerprint;
    private ProgressDialog progressDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.main);
        tvCount = (TextView) findViewById(R.id.tvCount);
        tvTime = (TextView) findViewById(R.id.tvTime);
        tvSuccessCount = (TextView) findViewById(R.id.tvSuccessCount);
        tvFailCount = (TextView) findViewById(R.id.tvFailCount);

        //读卡按钮
        buttonReadCard = (Button) findViewById(R.id.buttonReadCard);
        cbReadCardFp = (CheckBox) findViewById(R.id.cbReadCardFp);
        cbReadCardFp.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                boolReadFringerprint = isChecked;
            }
        });
        listenerReadCard = new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (reading == false) {
                    cardInfoView.cleanInfo();
                    startReadThread();
                    buttonReadCard.setText("停止");
                    tvMsg.setText("reading");
                } else {
                    stopRead();
                    tvMsg.setText("stop");
                    buttonReadCard.setText("读卡");
                }
            }
        };
        buttonReadCard.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolReadFringerprint = cbReadCardFp.isChecked();
                listenerReadCard.onClick(null);
            }
        });

        tvMsg = (TextView) findViewById(R.id.tvMsg);

        buttonExit = (Button) findViewById(R.id.buttonExit);
        buttonExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CloseReader();
                DemoActivity.this.finish();
            }
        });


        Button saveSamvID = (Button) findViewById(R.id.btnSaveSamvid);

        saveSamvID.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // 获取身份证读卡器唯一编号
                pd = ProgressDialog.show(DemoActivity.this, "提示",
                        "正在获取SamvID", true, false);
                new ReadSamvIDThread().start();
            }
        });


        Button btnFaceTest = (Button) findViewById(R.id.btnFaceTest);
        btnFaceTest.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (bmp == null) {
                    Toast.makeText(DemoActivity.this, "人脸比对请先读卡", Toast.LENGTH_SHORT).show();
                    return;
                }
                tvMsg.setText("stop");
                buttonReadCard.setText("读卡");
                if (ReadCardThreadhandler != null) {
                    ReadCardThreadhandler.StopRead();
                    ReadCardThreadhandler = null;
                }
                Intent intent = new Intent(DemoActivity.this, TakePhotoActivity.class);
                //Intent intent = new Intent(MainActivity.this,FaceTestActivity.class); //动态识别版 仅适用于V1算法
                TakePhotoActivity.img = util.bitmap2ByteArray(bmp);
                //intent.putExtra("img_byte",util.bitmap2ByteArray(bmp));
                intent.putExtra("ALGORITHM_VERSION", ALGORITHM_VERSION);
                startActivity(intent);
            }
        });

        Button btnReset = (Button) findViewById(R.id.btnReset);
        btnReset.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                if (reading)
                    listenerReadCard.onClick(null);
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        eclipseTime = 0;
                        ReadCount = 0;
                        SuccessCount = 0;
                        FailCount = 0;
                        LocalSharedPreferences.setString(getApplicationContext(), SPNameInterface.SP_TIME, "0");
                        LocalSharedPreferences.setString(getApplicationContext(), SPNameInterface.SP_COUNT, "0");
                        LocalSharedPreferences.setString(getApplicationContext(), SPNameInterface.SP_SUCCESS, "0");
                        LocalSharedPreferences.setString(getApplicationContext(), SPNameInterface.SP_FAIL, "0");
                        tvCount.setText("次数：" + ReadCount);
                        tvFailCount.setText("失败：" + FailCount);
                        tvSuccessCount.setText("成功：" + SuccessCount);
                        tvTime.setText("时间：" + util.formatDuringm(0));
                    }
                }, 1000);

            }
        });

        Button btnCpu = (Button) findViewById(R.id.btnCpu);
        btnCpu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (reading) {
                    stopRead();
                    MyUtils.sleep(1000);
                }
                tvMsg.setText("");
                OpenReader();
                byte[] ret = idCardReaderModule.MF_GET_SNR();
                if (ret != null) {
                    tvMsg.setText("cardNo=" + util.bytesToHexString(ret));
                }
            }
        });

        Button btnScan = (Button) findViewById(R.id.btnScan);
        btnScan.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(DemoActivity.this, TestScanActivity.class));
            }
        });


        Button btnFp = (Button) findViewById(R.id.Fingerprint);
        btnFp.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                new FindFpModuleAsyncTask(DemoActivity.this, new FindFpModuleAsyncTask.OnFinish() {
                    @Override
                    public void onFinish(boolean result, String value) {
                        if (result) {
                            startActivity(new Intent(DemoActivity.this, FPTestActivity.class));
                        } else {
                            Toast.makeText(DemoActivity.this, "打开指纹模块失败，" + value, Toast.LENGTH_SHORT).show();
                        }
                    }
                }).execute();

            }
        });

        final Button btnM1Test = (Button) findViewById(R.id.buttonM1Test);

        btnM1Test.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                startActivity(new Intent(DemoActivity.this, ReadM1CardActivity.class));
            }
        });

        if (mediaPlayer == null)
            mediaPlayer = MediaPlayer.create(this, R.raw.b);//读卡声音
        cardInfoView = new CardInfoView(this);
        cardInfoView.cleanInfo();
        idCardReaderModule = IDCardReaderModule.getInstance(this);
        //带nfc的机器需要关闭nfc才可以读身份证
        if (idCardReaderModule.hasNfc(this))
            idCardReaderModule.closeNFC();

        btnIdCardRead = (Button) findViewById(R.id.btn_id_card_read);
        btnIdCardRead.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(DemoActivity.this, IdCardRead01Activity.class));
                finish();
            }
        });

        new OpenReaderAsync().execute();

    }//onCreat()


    @Override
    protected void onResume() {
        super.onResume();
        eclipseTime = Integer.parseInt(LocalSharedPreferences.getString(getApplicationContext(), SPNameInterface.SP_TIME, "0"));
        ReadCount = Integer.parseInt(LocalSharedPreferences.getString(getApplicationContext(), SPNameInterface.SP_COUNT, "0"));
        SuccessCount = Integer.parseInt(LocalSharedPreferences.getString(getApplicationContext(), SPNameInterface.SP_SUCCESS, "0"));
        FailCount = Integer.parseInt(LocalSharedPreferences.getString(getApplicationContext(), SPNameInterface.SP_FAIL, "0"));


        tvCount.setText("次数：" + ReadCount);
        tvFailCount.setText("失败：" + FailCount);
        tvSuccessCount.setText("成功：" + SuccessCount);
        tvTime.setText("时间：" + util.formatDuringm(eclipseTime * 1000));

    }


    @Override
    protected void onPause() {
        stopRead();
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        CloseReader();
        FaceHandle.getFaceSDKInstance(ALGORITHM_VERSION).deinit();
        if (mediaPlayer != null) {
            mediaPlayer.release();
            mediaPlayer = null;
        }
        super.onDestroy();
    }

    /**
     * 关闭读卡器
     *
     * @Title CloseReader
     */
    private void CloseReader() {
        stopRead();
        idCardReaderModule.close();
    }


    private void stopRead() {
        //停止读卡线程
        if (ReadCardThreadhandler != null) {
            ReadCardThreadhandler.StopRead();
            try {
                ReadCardThreadhandler.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ReadCardThreadhandler = null;
        }
    }

    /**
     * 打开读卡器
     *
     * @Title OpenReader
     */
    private void OpenReader() {
        if (!idCardReaderModule.isOpen())
            idCardReaderModule.open();
    }


    void startReadThread() {
        reading = true;
        eclipseTime = Integer.parseInt(LocalSharedPreferences.getString(getApplicationContext(), SPNameInterface.SP_TIME, "0"));
        ReadCardThreadhandler = new ReadCardThread();
        ReadCardThreadhandler.start();
    }

    //读卡线程
    class ReadCardThread extends Thread {
        public void run() {
            OpenReader();
            if (!idCardReaderModule.isOpen()) {
                reading = false;
                idCardReaderModule.close();
                Log.e("ReadCardThread", "读卡器打开失败");
            }
            new UpdateTimerThread().start();

            while (reading) {
                try {
                    //getIDcardInfo()只读身份证信息，不读取指纹信息。 等同于getIDcardInfo(false, true, false);
                    IDCardReaderRetInfo retInfo;
                    if (!boolReadFringerprint)//是否需要读指纹
                        retInfo = idCardReaderModule.getIDcardInfo();
                    else
                        retInfo = idCardReaderModule.getIDcardInfo(false, true, true);

                    //读取指纹信息，读卡时间会稍长  可参考指纹的activity中读取身份证指纹按钮的实现
                    //IDCardReaderRetInfo retInfo = idCardReaderModule.getIDcardInfo(boolSameCardReadOnce, boolDecodePhoto, boolReadFringerprint);
                    //samvID=idCardReaderModule.getSamvIDString();//获取公安部二代证模块编号
                    //String appendAddress=idCardReaderModule.getAppendAddress();//获取身份证内的追加地址信息
                    if (retInfo.errCode == IDCardReaderRetInfo.ERROR_OK) {
                        //if(boolReadFringerprint)//仅测试时读取追加信息
                        //	retInfo.card.setAppendAddress(idCardReaderModule.getAppendAddress());
                        mHandler.obtainMessage(ReadOnceDone, retInfo.card).sendToTarget();
                        status = "";
                        Thread.sleep(500);
                    } else if (retInfo.errCode == IDCardReaderRetInfo.ERROR_RECV_FINDCARD) {
                        Log.e("ReadCardThread", "通信错误,重新打开读卡器");
                        idCardReaderModule.close();
                        Thread.sleep(3000);
                        idCardReaderModule.open();
                        if (!idCardReaderModule.isOpen()) {
                            reading = false;
                            idCardReaderModule.close();
                            Log.e("ReadCardThread", "读卡器打开失败");
                        }
                    } else {
                        status = util.bytesToHexString(new byte[]{retInfo.sw1, retInfo.sw2, retInfo.sw3});
                        mHandler.obtainMessage(ReadOnceDone, null).sendToTarget();
                        Thread.sleep(200);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }//while

            mHandler.obtainMessage(ReadThreadDone).sendToTarget();

        }//run

        public void StopRead() {
            reading = false;
            interrupted();
        }

    }//class


    //主要通过IDCard对象函数显示身份证信息和照片，
    public void showIDcardInfo(IDCard card) {
        ReadCount++;
        LocalSharedPreferences.setString(getApplicationContext(), SPNameInterface.SP_COUNT, "" + ReadCount);
        cardInfoView.showCardView(card);
        if (card != null) {
            util.Beep(mediaPlayer, this);
            SuccessCount++;
            LocalSharedPreferences.setString(getApplicationContext(), SPNameInterface.SP_SUCCESS, "" + SuccessCount);

        } else {
            FailCount++;
            LocalSharedPreferences.setString(getApplicationContext(), SPNameInterface.SP_FAIL, "" + FailCount);
        }
        tvCount.setText("次数：" + ReadCount);
        tvFailCount.setText("失败：" + FailCount);
        tvSuccessCount.setText("成功：" + SuccessCount);
    }


    class UpdateTimerThread extends Thread {
        public void run() {
            while (reading) {
                mHandler.obtainMessage(UpDateTime).sendToTarget();
                util.sleep(1000);
            }
        }
    }

    class ReadSamvIDThread extends Thread {
        public void run() {
            OpenReader();
            int tryTimes = 20;
            while (tryTimes > 0) {
                try {
                    String samvIDString = idCardReaderModule.getSamvIDString();
                    if (samvIDString != null && !samvIDString.isEmpty()) {
                        mHandler.obtainMessage(ReadSamvDone, samvIDString).sendToTarget();
                        return;
                    }
                    tryTimes--;
                    Thread.sleep(100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }//while
            mHandler.obtainMessage(ReadSamvDone, null).sendToTarget();
        }//run

    }//class


    class OpenReaderAsync extends AsyncTask<Void, Void, Boolean> {

        @Override
        protected Boolean doInBackground(Void... voids) {
            idCardReaderModule.open();
            return idCardReaderModule.isOpen();
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            setupProgressDialog("正在打开读卡器，请稍等", null);
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            try {
                progressDialog.dismiss();
            } catch (Exception e) {
            }
            if (!aBoolean) {
                Toast.makeText(DemoActivity.this, "读卡器打开失败", Toast.LENGTH_SHORT).show();
            }

            new FaceAuthAsync(DemoActivity.this, FaceHandle.getFaceSDKInstance(ALGORITHM_VERSION)).setOnfinish(new FaceAuthAsync.OnFinish() {
                @Override
                public void onDone(boolean initOk, int errCode) {
                    if (!initOk)
                        Toast.makeText(DemoActivity.this, "人脸初始化错误，errcode=" + errCode, Toast.LENGTH_SHORT).show();
                }
            }).execute();
        }
    }


    void setupProgressDialog(String msg, DialogInterface.OnClickListener listener) {
        progressDialog = new ProgressDialog(this, AlertDialog.THEME_HOLO_LIGHT);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setMessage(msg);
        progressDialog.setCancelable(false);
        if (listener != null)
            progressDialog.setButton("取消", listener);
        progressDialog.show();
    }

    private class CardInfoView {
        private TextView textViewName;
        private TextView textViewSex;
        private TextView textViewNation;
        private TextView textViewBirthday;
        private TextView textViewAddress;
        private TextView textViewPIDNo;
        private TextView textViewGrantDept;
        private TextView textViewUserLife;
        private TextView textViewStatus;
        private TextView tvFpAndAppendAdd;
        private ImageView imageViewPhoto;

        public CardInfoView(Activity activity) {
            textViewName = (TextView) findViewById(R.id.textViewName);
            textViewSex = (TextView) findViewById(R.id.textViewSex);
            textViewNation = (TextView) findViewById(R.id.textViewNation);
            textViewBirthday = (TextView) findViewById(R.id.textViewBirthday);
            textViewAddress = (TextView) findViewById(R.id.textViewAddress);
            textViewPIDNo = (TextView) findViewById(R.id.textViewPIDNo);
            textViewGrantDept = (TextView) findViewById(R.id.textViewGrantDept);
            textViewUserLife = (TextView) findViewById(R.id.textViewUserLife);
            textViewStatus = (TextView) findViewById(R.id.textViewStatus);
            tvFpAndAppendAdd = (TextView) findViewById(R.id.tvFpAndAppendAdd);
            imageViewPhoto = (ImageView) findViewById(R.id.imageViewPhoto);
        }

        public void showCardView(IDCard idcard) {

            textViewStatus.setText(getString(R.string.sdtstatus) + status);

            if (idcard != null) {
                if (idcard.getCardType() == IDCard.CARDTYPE_NORMAL || idcard.getCardType() == IDCard.CARDTYPE_HMT) {//普通居民身份证或港澳台居住证
                    textViewName.setText(getString(R.string.sdtname) + idcard.getName());
                    textViewSex.setText(getString(R.string.sdtsex) + idcard.getSex());
                    if (idcard.getCardType() == IDCard.CARDTYPE_HMT) {
                        textViewNation.setText("通行证号:" + idcard.getPassID() + "\r\n签发次数:" + idcard.getIssuesTimes());
                    } else {
                        textViewNation.setText(getString(R.string.sdtnation) + idcard.getNation());
                    }

                    textViewBirthday.setText(getString(R.string.sdtbirthday)
                            + idcard.getYearOfBirth() + "年"
                            + idcard.getMonthOfBirth() + "月"
                            + idcard.getDayOfBirth() + "日");
                    textViewAddress.setText(getString(R.string.sdtaddress) + idcard.getAddress());
                    textViewPIDNo.setText(getString(R.string.sdtpidno) + idcard.getIDCardNo());
                    textViewGrantDept.setText(getString(R.string.sdtgrantdept) + idcard.getGrantDept());
                    textViewUserLife.setText(getString(R.string.sdtuserlife) + idcard.getUserLifBebinWithPoint() + "-" + idcard.getUserLifEndWithPoint());
                    textViewStatus.setText(getString(R.string.sdtstatus));

                } else {//外国人居住证
                    ForeignerIDCard card = idcard.getForeignerIDCard();
                    textViewName.setText("姓名:" + card.getEngName() + "\r\n" + card.getCHNName());
                    String sex = card.getSex();
                    if (sex.equals("女")) sex += "/F";
                    else sex += "/M";
                    textViewSex.setText(getString(R.string.sdtsex) + sex);
                    textViewNation.setText("国籍:" + CountryCode.getContryByCode(card.getNation()) + "/" + card.getNation());
                    textViewBirthday.setText(getString(R.string.sdtbirthday)
                            + card.getBirthdayWithSeparator("."));
                    textViewAddress.setText("有效日期:" + card.getUserLifBebinWithPoint() + "-" + card.getUserLifEndWithPoint());
                    textViewPIDNo.setText("永久居留证号码:" + card.getIDCardNo());
                    String grantDep = card.getGrantDep();
                    if (grantDep.equals("1500"))
                        grantDep += "  公安部/Ministry of Public Security";
                    textViewGrantDept.setText("签发机关代码:" + grantDep);
                    textViewUserLife.setText("证件版本号:" + card.getCertVol());
                    textViewStatus.setText(getString(R.string.sdtstatus));
                }

                if (boolReadFringerprint) {
                    tvFpAndAppendAdd.setVisibility(View.VISIBLE);
                    tvFpAndAppendAdd.setText(getString(R.string.append_msg) + idcard.getFpDescription() + "," + idcard.getAppendAddress());
                } else {
                    tvFpAndAppendAdd.setText(getString(R.string.append_msg) + "未读指纹信息" + "," + idcard.getAppendAddress());
                    tvFpAndAppendAdd.setVisibility(View.GONE);
                }


                try {
                    //int result = idcard.decodeResult;
                    if (bmp != null) bmp.recycle();
                    bmp = idcard.getPhoto();
                    if (bmp != null) {//保存照片
                        //MediaStore.Images.Media.insertImage(getContentResolver(), bmp, "zp", "");
                        //String bmpPath = getFileStreamPath("photo.bmp").getAbsolutePath();
                        //util_File.copyfile(bmpPath,util_File.getExternalPath()+idcard.getName()+".bmp");
                    } else {
                        Resources res = getResources();
                        bmp = BitmapFactory.decodeResource(res, R.drawable.photo);
                    }
                    imageViewPhoto.setImageBitmap(bmp);
                    ////log.debug("decode wlt finish");
                    System.gc();
                } catch (Exception ioe) {
                    ioe.printStackTrace();
                    //log.debug("photo display error:" + ioe.getMessage());
                    //tvMessage.setText("状态：照片显示错" + ioe.getMessage());
                }
            }
        }

        public void cleanInfo() {
            textViewName.setText(getString(R.string.sdtname));
            textViewSex.setText(getString(R.string.sdtsex));
            textViewNation.setText(getString(R.string.sdtnation));
            textViewBirthday.setText(getString(R.string.sdtbirthday));
            textViewAddress.setText(getString(R.string.sdtaddress));
            textViewPIDNo.setText(getString(R.string.sdtpidno));
            textViewGrantDept.setText(getString(R.string.sdtgrantdept));
            textViewUserLife.setText(getString(R.string.sdtuserlife));
            tvFpAndAppendAdd.setText(getString(R.string.append_msg));
            imageViewPhoto.setImageResource(R.drawable.photo);
            textViewStatus.setText(getString(R.string.sdtstatus));
            bmp = null;
        }


    }

}